﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MVCManage.Model.Base
{
    public class BaseDAL<T> where T : class, new()
    {
      
       
        public DbContext dbContext = DbContextFactory.Create();
        public void Add(T t) {
             dbContext.Set<T>().Add(t);
        }
        public void Add(List<T> list)
        {
            dbContext.Set<T>().AddRange(list);
        }

        public void Update(T t) {
            dbContext.Set<T>().AddOrUpdate(t);
        }
        public void Delete(T t) {
            dbContext.Set<T>().Remove(t);
        }
        public void Deletes(List<T> t) {
            dbContext.Set<T>().RemoveRange(t);
        }
        public IQueryable<T> Query() {
            return dbContext.Set<T>().AsQueryable();
        }
        public bool SaveChanges() {
        
            return dbContext.SaveChanges() >0;
        }
    }
}
